<!--演示点击按钮传值-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>emit和on</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <input type="text" v-model="notify">
    <button @click="test">发送信息</button>
    <h1 v-for="item in list">{{ item }}</h1>
    {{ hi }}
</div>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                list: [1, 2, 3],
                hi: {
                    m: 1
                },
                msg: '$emit是发布者\n$on是订阅者',
                notify: '今天吃什么好呢？'
            }
        },
        created() {

        },
        mounted() {
            setTimeout(() => {
                this.list[0] = 9
                this.hi.a = 10
                console.log(this.list, this.hi)
            }, 3000)
            console.log(this.list)
            console.log(localStorage.getItem('aaa'))
            // 先订阅公众号（不然无法接收消息）
            this.$on("msg", (val) => {
                this.msg = val
            })
            //请打开控制台，观察打印数值
            this.$on("msg", (val) => {
                console.log("订阅者1", val)
            })
            this.$on("msg", (val) => {
                console.log("订阅者2", val)
            })
            this.$on("msg", (val) => {
                console.log("订阅者3", val)
            })
        },
        methods: {
            test() {
                //推送公众号 订阅公众号的人会收到消息
                this.$emit("msg", this.notify)
            }
        }
    })
</script>
</body>
</html>